global_defs {
  router_id LVS_DEVEL
}

vrrp_script check_haproxy {
  script "killall -0 haproxy"
  interval 3
  weight -2
  fall 10
  rise 2
}

vrrp_instance VI_1 {
  state {% if haproxy_servers[0] in ansible_default_ipv4.address %}MASTER{% else %}BACKUP{% endif %}

  interface bond0
  virtual_router_id 51
  priority {% if haproxy_servers[0] in ansible_default_ipv4.address %}100{% else %}{{ 99 | random(seed=ansible_hostname,start=1, step=1) }}{% endif %}

  advert_int 1
  authentication {
    auth_type PASS
    auth_pass {{ lookup('password', '' + group_names[-1] + ':authentication length=14 chars=ascii_letters,digits') }}
  }

  unicast_src_ip {{ ansible_default_ipv4.address }}
  unicast_peer {
{% for ip in haproxy_servers %}
{% if ip not in ansible_default_ipv4.address %}
    {{ ip }}
{% endif %}
{% endfor %}
  }
  virtual_ipaddress {
    {{ haproxy_keepalived_vip }}
  }
  track_script {
    check_haproxy
  }
}
